HTMLify
Remove Outermost Parentheses.cpp
Views: 1 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include<bits/stdc++.h> using namespace std; class Solution { public: string removeOuterParentheses(string s) { int count = 0; string ans = ""; bool flag = true; for(int i = 0; i<s.size(); i++){ if(s[i] == '('){ count++; } else if(s[i] == ')'){ count--; } if( count==1 && flag == true){ flag = false; continue; } if(count == 0 && flag ==false){ flag = true; continue; } ans += s[i]; } return ans; } }; |